//
//  SMHHomeViewModel.swift
//  SMHCommerce
//
//  Created by lvzhao on 2020/1/9.
//  Copyright © 2020 lvzhao. All rights reserved.
//

import UIKit
import Alamofire
import SwiftyJSON
import Alamofire
import HandyJSON

class SMHHomeViewModel: LZBaseViewModel {

    deinit {
        print("\(self)释放了");
    }
    
    override init() {
        super.init()
    }
    
    func getHomeData(isFrist :Bool) {
        
//        Alamofire.request("https://api.cpc.capital/getIndexInfo",method: .get).responseJSON { (response) in
////            print(response)
//        }
//
//        Alamofire.request("https://api.sumaihuo.shop/user/login",method: .post, parameters: ["mailOrMobile":"18595961788","password":"lv123456"]).responseJSON { (response) in
//
////            print(response)
//        }

        
        APINetWork.request(.listMain("", 1, 15), success: { result in
            let dict = JSON(result)
            guard dict["status"].intValue == 200 else {
                print("请求失败")
                return
            }
            let dataDictionary = dict["data"].dictionary
            //  字典转成模型
            if let items = dataDictionary!["records"]?.arrayObject {
                for item in items {
                    let dataDict = item as? [String : Any]
                    if let object = SMHProductModel.deserialize(from: dataDict) {
                        // ...
                        self.dataArray.append(object)
                    }
                }
            }
           self.publishSubject.onNext(1)
        }, error: { code in}) { (error) in}
        
        
    }
    
//     Alamofire.request(self.urlStringPost, method: .post, parameters: parameters, encoding: URLEncoding.default, headers: nil).responseJSON { response in
//                    if let json = response.result.value {
//                        print("JSON\(json)");
//                    }
//                }
//
}
